import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import '../components/PageWrap.dart';

class StackAndPositionedLn extends StatefulWidget {
  const StackAndPositionedLn({super.key});

  @override
  State<StackAndPositionedLn> createState() => _StackAndPositionedLnState();
}

class _StackAndPositionedLnState extends State<StackAndPositionedLn> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(
            "层叠布局（Stack、Positioned）", // 设置标题文本
            style: TextStyle(
              color: Colors.white, // 设置标题字体颜色
            ),
          ),
          iconTheme: IconThemeData(
            color: Colors.white, // 设置返回图标颜色
          ),
          backgroundColor: Colors.deepPurple, // 设置AppBar背景颜色
        ),
        body: Stack(
          alignment:Alignment.center ,
          fit: StackFit.expand, //未定位widget占满Stack整个空间
          children: <Widget>[
            Positioned(
              left: 18.0,
              child: Text("I am Jack"),
            ),
            Container(child: Text("Hello world",style: TextStyle(color: Colors.white)),
              color: Colors.red,
            ),
            Positioned(
              top: 18.0,
              child: Text("Your friend"),
            )
          ],
        )

        // ConstrainedBox(
        //   constraints: BoxConstraints.expand(),
        //   child: Stack(
        //     alignment: Alignment.center, //指定未定位或部分定位widget的对齐方式
        //     children: <Widget>[
        //       Container(
        //         child:
        //             Text("Hello world", style: TextStyle(color: Colors.white)),
        //         color: Colors.red,
        //       ),
        //       Positioned(
        //         left: 18.0,
        //         child: Text("I am Jack"),
        //       ),
        //       Positioned(
        //         top: 18.0,
        //         child: Text("Your friend"),
        //       )
        //     ],
        //   ),
        // )
    );

  }
}
